package com.example.cinema.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.cinema.entity.Movie;
import org.apache.ibatis.annotations.Many;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author yc138
 * @since 2024-08-26
 */
@RestController
public interface MovieMapper extends BaseMapper<Movie> {

    @Select("select * from movie order by id desc limit 0,5")
    List<Movie> getFiveMovie();


    @Select("select * from movie where id = #{id}")
    @Results(id = "rm1",value = {
            @Result(column = "id",property = "id",id = true),
            @Result(column = "id",property = "stills",many = @Many(
                    select = "com.example.cinema.mapper.StillMapper.selectByMid"
            )),
            @Result(column = "id",property = "trailers",many = @Many(
                    select = "com.example.cinema.mapper.TrailerMapper.selectByMid"
            ))
    })
    Movie findMovieStillById(int id);

    @Select("select * from movie where id = #{id}")
    Movie selectByIdlj(int id);
}
